using System;
using System.Collections;
using UnityEngine;

public class Trailer_Chaos_VentManager : MonoBehaviour
{
	public bool InVentAnimation;

	public bool SpinKris;

	public GameObject idleSmoke;

	[SerializeField]
	private float JumpArcHeight = 3f;

	[SerializeField]
	private float JumpDuration = 0.5f;

	private Vector2 lastPosition;

	[SerializeField]
	private Vector3 JumpStartPos;

	public Vector3 JumpEndPos;

	private float timeElapsed;

	private bool isMoving;

	private bool isVerticalVent;

	private ParticleSystem storedSmoke;

	public AudioSource source;

	public static Trailer_Chaos_VentManager instance;

	private Vector2 initialDirection;

	private void Awake()
	{
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		instance = this;
		Trailer_Chaos_Vent[] array = Object.FindObjectsByType<Trailer_Chaos_Vent>((FindObjectsSortMode)0);
		foreach (Trailer_Chaos_Vent trailer_Chaos_Vent in array)
		{
			Object.Instantiate<GameObject>(idleSmoke).transform.position = ((Component)trailer_Chaos_Vent).transform.position;
		}
	}

	private void Update()
	{
		ArcUpdate();
	}

	private void ArcUpdate()
	{
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		if (isMoving)
		{
			timeElapsed += Time.deltaTime;
			float num = timeElapsed / JumpDuration;
			Vector2 val = CalculateArcPosition(num);
			((Component)PlayerManager.Instance).transform.position = Vector2.op_Implicit(val);
			RotatePlayerDuringArc(num);
			if (num >= 1f)
			{
				isMoving = false;
				InVentAnimation = false;
				timeElapsed = 0f;
				((Component)PlayerManager.Instance).transform.position = JumpEndPos;
				PlayerManager.Instance._PlayerState = PlayerManager.PlayerState.Game;
				SpinKris = false;
				CameraManager.instance.FollowPlayerY = true;
				storedSmoke.Stop();
			}
			else if (isVerticalVent)
			{
				CameraManager.instance.FollowPlayerY = true;
			}
			else
			{
				CameraManager.instance.FollowPlayerY = false;
			}
		}
	}

	private void RotatePlayerDuringArc(float t)
	{
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		float num = Mathf.Lerp(0f, 360f, t) * (MathF.PI / 180f);
		Vector2 rotation = default(Vector2);
		((Vector2)(ref rotation))._002Ector(initialDirection.x * Mathf.Cos(num) - initialDirection.y * Mathf.Sin(num), initialDirection.x * Mathf.Sin(num) + initialDirection.y * Mathf.Cos(num));
		PlayerManager.Instance._PMove.RotatePlayerAnim(rotation);
	}

	public IEnumerator StartVent(Vector3 startPos, Vector3 endPos, bool isVertical, ParticleSystem storedsmoke)
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		if (!InVentAnimation)
		{
			storedSmoke = storedsmoke;
			InVentAnimation = true;
			PlayerManager.Instance._PlayerState = PlayerManager.PlayerState.Cutscene;
			initialDirection = PlayerManager.Instance._PMove.CurrentPlayerRotation;
			while (Vector3.Distance(((Component)PlayerManager.Instance).transform.position, startPos) > 0.1f)
			{
				yield return null;
				((Component)PlayerManager.Instance).transform.position = Vector3.Lerp(((Component)PlayerManager.Instance).transform.position, startPos, 15f * Time.deltaTime);
			}
			yield return (object)new WaitForSeconds(0.25f);
			storedSmoke.Play();
			isVerticalVent = isVertical;
			source.Play();
			JumpStartPos = ((Component)PlayerManager.Instance).transform.position;
			JumpEndPos = endPos;
			timeElapsed = 0f;
			SpinKris = true;
			isMoving = true;
		}
	}

	private Vector2 CalculateArcPosition(float t)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		Vector2 val = Vector2.Lerp(Vector2.op_Implicit(JumpStartPos), Vector2.op_Implicit(JumpEndPos), t);
		float num = JumpArcHeight * Mathf.Sin(MathF.PI * t);
		return new Vector2(val.x, val.y + num);
	}
}
